/*

 * WorkerSpace.h
 *
 *  Created on: 28-10-2011
 *      Author: cristian
 */

#ifndef WORKERSPACE_H_
#define WORKERSPACE_H_
#include "Ambiente.h"
#include <sstream>
#include <string>
#include <typeinfo>
#include "XmlUtils.h"
#include "WorkerSpaceException.h"
#include "HttpHeader.h"

#define MAX_THREAD_MUL  3;
class WorkerSpace: public Ambiente<WorkerSpace> {
private:

	list<string>* servers;

	unsigned int id;
	unsigned int size;
	std::string nombre;
	std::string descripcion;
	Logger* logger;
	WorkerSpace* root;
	unsigned int max_threads;
	void setMaxThreads();
	void stopWorkers();
	void work(void* object);
	void clearAmbiente();


public:
	WorkerSpace(WorkerSpace* root);
	virtual ~WorkerSpace();
	std::string getDescripcion() const;
	unsigned int getId() const;
	std::string getNombre() const;
	void setDescripcion(std::string descripcion);
	void setId(unsigned int id);
	void setNombre(std::string nombre);
	static void* start(void* object);
	WorkerSpace *getRoot() const;
	void setRoot(WorkerSpace *root);
	void addWorkerSpace(unsigned int x, unsigned int y, WorkerSpace* worker);
	void addWorkerSpace(WorkerSpace* worker);
	unsigned int getSize() const;
	void stopWorker(unsigned int x, unsigned int y);
	void stopWorker(unsigned int id);
	void stopWorker(WorkerSpace* workerspace);
	void stopWorker();
	void startWorker(unsigned int x, unsigned int y);
	unsigned int getMaxThreads() const;
	void setMaxThreads(unsigned int max_threads);
	void runAllWorkers();
	bool moveMe(WorkerSpace* workerspace, unsigned int x2, unsigned int y2);
	void close();
	void listening();
	string* createXmlStatus();
	string* sendData(string host, int port, string* data);

};

#endif /* WORKERSPACE_H_ */
